package com.abel.roommanager.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.abel.roommanager.pojo.Repair;
import com.abel.roommanager.service.RepairService;

@Controller
@RequestMapping("/repair")
public class RepairController {
	@Autowired
	private RepairService repairService;
	@RequestMapping("/findLossByRid")
	@ResponseBody
   public List<Repair> findLossByRid(int roomno) {
		
	return repairService.findLossByRid(roomno);
  }
	@RequestMapping("/add")
	@ResponseBody
	public int addRepair(Repair repair) {
		System.out.println(repair);
		Date date=new Date();
		SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy-MM-dd");
		String lossdate=sDateFormat.format(date);
		repair.setLossdate(lossdate);
		return repairService.addRepair(repair);
	}
	@RequestMapping("/solve")
	@ResponseBody
	public int repair(int id) {
		return repairService.repairDevice(id);
	}
}
